<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script type="text/javascript">


  let romanToInt = function (s) {
    let a = [
      {
        name: 'I',
        number: 1
      }, {
        name: 'V',
        number: 5
      }, {
        name: 'X',
        number: 10
      }, {
        name: 'L',
        number: 50
      }, {
        name: 'C',
        number: 100
      }, {
        name: 'D',
        number: 500
      }, {
        name: 'M',
        number: 1000
      },
    ];
    let sum = 0;
    let sizeNum = [];
    for (let i = 0; i < s.length; i++) {
      let num = s.substring(i, i + 1);
      for (let j = 0; j < a.length; j++) {
        if (num === a[j].name) {
          sizeNum[i] = a[j].number;
        }
      }
    }

    for (let i = 1; i <= sizeNum.length; i++) {
      if (sizeNum[i - 1] < sizeNum[i]) {
        sum += sizeNum[i] - sizeNum[i - 1];
        i++;
      }else{
        sum+=sizeNum[i-1];
      }

    }

    document.write(sum);
  };
  romanToInt('MCMXCIV');

</script>
</body>
</html>